﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using MiniFox.Data.EntityFramework;
using MiniFox.Data.EntityFramework.MySql;

namespace DMC.Data.Entities.MySql;

public partial class DmcContext : MySqlDbContext
{
    public DmcContext(DbContextOptions<DmcContext> options)
        : base("DmcContext", options)
    {
    }

    public virtual DbSet<Attachment> Attachment { get; set; }

    public virtual DbSet<DsConnection> DsConnection { get; set; }

    public virtual DbSet<DtExcelExport> DtExcelExport { get; set; }

    public virtual DbSet<DtExcelImport> DtExcelImport { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .UseCollation("utf8mb4_0900_ai_ci")
            .HasCharSet("utf8mb4");

        modelBuilder.Entity<Attachment>(entity =>
        {
            entity.HasKey(e => e.FileId).HasName("PRIMARY");

            entity.ToTable("attachment");

            entity.Property(e => e.FileId)
                .HasMaxLength(64)
                .HasColumnName("file_id");
            entity.Property(e => e.ContentLength).HasColumnName("content_length");
            entity.Property(e => e.Data).HasColumnName("data");
            entity.Property(e => e.ExtName)
                .HasMaxLength(10)
                .HasColumnName("ext_name");
            entity.Property(e => e.FileName)
                .HasMaxLength(300)
                .HasColumnName("file_name");
            entity.Property(e => e.MimeType)
                .HasMaxLength(100)
                .HasColumnName("mime_type");
        });

        modelBuilder.Entity<DsConnection>(entity =>
        {
            entity.HasKey(e => e.Name).HasName("PRIMARY");

            entity.ToTable("ds_connection");

            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .HasColumnName("name");
            entity.Property(e => e.ConnectionString)
                .HasMaxLength(1024)
                .HasColumnName("connection_string");
            entity.Property(e => e.ProviderName)
                .HasMaxLength(50)
                .HasColumnName("provider_name");
        });

        modelBuilder.Entity<DtExcelExport>(entity =>
        {
            entity.HasKey(e => e.Name).HasName("PRIMARY");

            entity.ToTable("dt_excel_export");

            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .HasColumnName("name");
            entity.Property(e => e.CreateTime)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasColumnType("timestamp")
                .HasColumnName("create_time");
            entity.Property(e => e.DataLoader)
                .HasMaxLength(100)
                .HasColumnName("data_loader");
            entity.Property(e => e.ExcelFormat)
                .HasMaxLength(100)
                .HasDefaultValueSql("'XLS'")
                .HasColumnName("excel_format");
            entity.Property(e => e.MaxRowCountPerSheet)
                .HasDefaultValueSql("'65535'")
                .HasColumnName("max_row_count_per_sheet");
            entity.Property(e => e.Modules)
                .HasColumnType("json")
                .HasColumnName("modules");
            entity.Property(e => e.Sheets)
                .HasColumnType("json")
                .HasColumnName("sheets");
            entity.Property(e => e.Template)
                .HasMaxLength(500)
                .HasColumnName("template");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasColumnType("timestamp")
                .HasColumnName("update_time");
        });

        modelBuilder.Entity<DtExcelImport>(entity =>
        {
            entity.HasKey(e => e.Name).HasName("PRIMARY");

            entity.ToTable("dt_excel_import");

            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .HasColumnName("name");
            entity.Property(e => e.CreateTime)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasColumnType("timestamp")
                .HasColumnName("create_time");
            entity.Property(e => e.DataWriter)
                .HasMaxLength(100)
                .HasColumnName("data_writer");
            entity.Property(e => e.MaxImportFileSize)
                .HasDefaultValueSql("'104857600'")
                .HasColumnName("max_import_file_size");
            entity.Property(e => e.Modules)
                .HasColumnType("json")
                .HasColumnName("modules");
            entity.Property(e => e.PreImport).HasColumnName("pre_import");
            entity.Property(e => e.Sheets)
                .HasColumnType("json")
                .HasColumnName("sheets");
            entity.Property(e => e.Template)
                .HasMaxLength(500)
                .HasColumnName("template");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasColumnType("timestamp")
                .HasColumnName("update_time");
        });
        
        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
